//
//  XWXSqliteToolTests.m
//  XWXSqliteToolTests
//
//  Created by wxxu on 09/20/2017.
//  Copyright (c) 2017 wxxu. All rights reserved.
//

#import "XWXSqliteManager.h"
#import "XWXModel.h"
#import "XWXTestModel.h"
@import XCTest;

@interface Tests : XCTestCase

@end

@implementation Tests

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testCreateTable
{
    [XWXSqliteManager createTableWithModelClass:XWXTestModel.class withDBName:nil];
}

- (void)testInsertAndQueryModel
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self testInsertTable];
    });
    //    [self testQueryModel];
}

- (void)testUpdateModel
{
    NSString *condition = @"name = 'wxxu22'";
    XWXTestModel *testModel = [[XWXTestModel alloc] init];
    testModel.name = @"wxxu22";
    testModel.codeArea = @"55";
    NSArray *array = @[@"aaa",@"bbb",@"ccc"];
    testModel.array = array;
    
    [XWXSqliteManager updateWithModel:testModel withDBName:nil whereCondition:condition];
}

- (void)testUpdateModel2
{
    XWXTestModel *testModel = [[XWXTestModel alloc] init];
    testModel.name = @"wxxu33";
    testModel.codeArea = @"66";
    NSArray *array = @[@"aaa",@"bbb",@"ccc"];
    testModel.array = array;
    
    [XWXSqliteManager updateWithModel:testModel withDBName:nil columnName:@"name" relation:ColumnNameToValueRelationTypeEqual value:@"wxxu22"];
}

- (void)testDeleteModel
{
    NSString *condition = @"name = 'wxxu33'";
    XWXTestModel *testModel = [[XWXTestModel alloc] init];
    
    [XWXSqliteManager deleteWithModelClass:testModel.class withDBName:nil whereCondition:condition];
}

- (void)testDeleteModel2
{
    XWXTestModel *testModel = [[XWXTestModel alloc] init];
    
    [XWXSqliteManager deleteWithModelClass:testModel.class withDBName:nil columnName:@"name" relation:ColumnNameToValueRelationTypeEqual value:@"wxxu"];
}

- (void)testQueryModel
{
    NSArray *results = [XWXSqliteManager selectWithModelClass:XWXTestModel.class withDBName:nil];
    for (int i = 0; i < results.count; i++) {
        NSLog(@"%@", [NSString stringWithFormat:@"-----%@---------",results[i]]);
    }
}

- (void)testInsertTable
{
    XWXTestModel *testModel = [[XWXTestModel alloc] init];
    testModel.name = @"22";
    testModel.codeArea = @"afadfasdfa";
    testModel.cookies = @"123ajadjfalfjaafjasdlfja";
    testModel.age = 26;
    testModel.a = @"aaaaaaa";
    
    NSArray *array = @[@"aaa",@"bbb",@"ccc"];
    testModel.array = array;
    
    NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithArray:array];
    testModel.mutableArray = mutableArray;
    
    NSDictionary *dic = @{@"aa":@"aaaa",@"bb":@"bbbb"};
    testModel.dic = dic;
    
    NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"scroll_delete"]);
    testModel.iamgeData = imageData;
    
    XWXModel *model = [[XWXModel alloc] init];
    model.name = @"name";
    model.a11 = @"a11";
    model.codeArea11 = @"codeArea11";
    model.cookies11 = @"cookies11";
    
    [XWXSqliteManager insertWithModel:testModel withDBName:nil];
}

- (void)testDropTable
{
    [XWXSqliteManager dropTableWithModelClass:[XWXTestModel class] withDBName:nil];
}
@end

